package com.shenzhen.horselive.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;

import com.flqy.baselibrary.utils.GlideHelper;
import com.shenzhen.horselive.R;
import com.shenzhen.horselive.beans.MapRedPackageBean;
import com.shenzhen.horselive.common.utils.handler.IFilterHandler;
import com.shenzhen.horselive.databinding.DialogLoginBinding;
import com.shenzhen.horselive.databinding.DialogOpenHongbaoBinding;

public class OpenHongBaoDialog extends Dialog {


    private  OnOpenClick  onOpenClick;

    public OpenHongBaoDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    public OpenHongBaoDialog(Context context, int theme) {
        super(context, theme);
    }


    DialogOpenHongbaoBinding binding;
    MapRedPackageBean  mapRedPackageBean;
    public OpenHongBaoDialog(Context context, MapRedPackageBean mapRedPackageBean) {
        super(context, R.style.CommonDialog);
        //初始化
        this.onOpenClick = onOpenClick;
        this.mapRedPackageBean =mapRedPackageBean;
        binding = DialogOpenHongbaoBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        initViews();


    }

    public void setOnOpenClick(OnOpenClick onOpenClick) {
        this.onOpenClick = onOpenClick;
        binding.imgOpen.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onOpenClick!=null)
                {
                    binding.imgOpen.play();
                    onOpenClick.onOpen();
                }
            }
        });
    }

    private void initViews() {
        //初始化dialog
        GlideHelper.loadRoundImage(binding.imgUser,mapRedPackageBean.getHeadImg());
        binding.tvName.setText(mapRedPackageBean.getNickname());
        binding.imgOpen.setPaused(true);
//        1：平台红包，2：应用红包，3：广播红包
        if (mapRedPackageBean.getType()==1)
        {
            binding.tvType.setText("给你发了一个平台红包");
        }
        else if (mapRedPackageBean.getType()==2)
        {
            binding.tvType.setText("给你发了一个应用红包");
        }
        else if (mapRedPackageBean.getType()==3)
        {
            binding.tvType.setText("给你发了一个广播红包");
        }
        else
        {            binding.tvType.setText("给你发了一个红包");

        }
    }

    @Override
    public void dismiss() {
        super.dismiss();
        binding.imgOpen.pause();
    }

    @Override
    public void show() {
        super.show();
        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        layoutParams.width= ViewGroup.LayoutParams.WRAP_CONTENT;
        layoutParams.height= ViewGroup.LayoutParams.WRAP_CONTENT;
        getWindow().setAttributes(layoutParams);
    }





    public  interface  OnOpenClick{
        void  onOpen();
    }

}
